package siswar.driver;

import java.util.HashSet;
import java.util.Set;

import sisdroid.framework.SisDroidImpl;
import android.app.*;
import android.os.*;
import android.widget.*;

public class SisWarDriver extends Activity
{

	// HOOK for the framework.
	SisDroidImpl sisdroid;
	
	final Handler handler = new Handler();
	Thread worker;
	
	
	netObserver obs;
	
	final Runnable ugh = new Runnable()
	{
		public int msg = 0;
		public void run() 
		{
			TextView tv = (TextView) findViewById( R.id.logmessage );
			tv.setText( tv.getText() + "x" );	
		}
	};	
		
	
	 @Override
	 public boolean onTouchEvent(android.view.MotionEvent event)
	 {
		 TextView tv = (TextView) findViewById( siswar.driver.R.id.logmessage );
		 tv.setText( obs.netsInformation );	
		 return super.onTouchEvent( event );
	 };
	
    /** 
     * 
     * Called when the activity is first created. 
     * 
     * Spawns a thread then 
     * 
     * */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        obs = new netObserver();
        
    	sisdroid = new SisDroidImpl( new sisdroid.framework.SisClientFactory( this ) );
    	
    	sisdroid.setObserver( obs );
    	
        worker = new Thread(  new Runnable() {
			
			@Override
			public void run()
			{
				int i = 0;
				while ( true ) // Ever lasting thread!!!
				{
					i++;
					Set<String> filter = new HashSet<String>();
					
					sisdroid.Search( filter );
					
					try
					{
						Thread.sleep( 15000 );
					}
					catch (InterruptedException e) 
					{
						e.printStackTrace();
					}
					
					// handler.post( ugh );
					
				}
			}
		});
        
        worker.start();
    }
}